﻿using Emgu.CV.Features2D;
using Ozone.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Ozone.Views.SystemCenter.LiquidRatioMethod
{
    /// <summary>
    /// LiquidRatioMethodItem.xaml 的交互逻辑
    /// </summary>
    public partial class LiquidRatioMethodItem : Window
    {

        List<ObtainParam> ListSolutionBottles = new List<ObtainParam>();
        public LiquidRatioMethodItem()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 取消
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCommCancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCommOK_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        /// <summary>
        /// 添加溶液配置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSolutionSet_Click(object sender, RoutedEventArgs e)
        {
            string tag = ((Button)sender).Tag.ToString();
            if (tag == "ADD")
            {
                ObtainParam itemMaterial = new ObtainParam();
                LiquidRatioMethodItemBottle form = new LiquidRatioMethodItemBottle(itemMaterial);
                if (form.ShowDialog() == true)
                {

                    //判断该配液瓶号是否已经配置过
                    bool exists = ListSolutionBottles.Exists(x => x.FBottleNo == form.obtainParam.FBottleNo);
                    if (exists)
                    {
                        if (MessageBox.Show("该溶液已在方法中配置", "提示",
                        MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
                        {

                        }
                        return;
                    }
                    else
                    {
                        ListSolutionBottles.Add(form.obtainParam);
                        dgSolution.ItemsSource = null;
                        dgSolution.ItemsSource = ListSolutionBottles;
                    }
                }
            }

            if (tag == "EDIT")
            {

                if (dgSolution.SelectedItem == null)
                {
                    if (MessageBox.Show("请选择一行数据进行修改", "提示",
                  MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
                    {

                    }
                    return;
                }
                int nIndex = dgSolution.Items.IndexOf(dgSolution.SelectedItem);

                ObtainParam itemMaterial = ListSolutionBottles[nIndex];


                LiquidRatioMethodItemBottle form = new LiquidRatioMethodItemBottle(itemMaterial);
                if (form.ShowDialog() == true)
                {
                    dgSolution.ItemsSource = null;
                    dgSolution.ItemsSource = ListSolutionBottles;

                }
            }

            if (tag == "DEL")
            {

                if (dgSolution.SelectedItem == null)
                {
                    if (MessageBox.Show("请选择一行数据进行删除", "提示",
                  MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
                    {

                    }
                    return;
                }
                int nIndex = dgSolution.Items.IndexOf(dgSolution.SelectedItem);

                if (MessageBox.Show("确认要删除吗", "提示",
                  MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
                    return;

                ListSolutionBottles.RemoveAt(nIndex);
                dgSolution.ItemsSource = null;
                dgSolution.ItemsSource = ListSolutionBottles;
            }

        }



    }
}

